<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <p>
        使用函数完成任意数字阶乘的计算
    </p>
    <input type="text" placeholder="请输入一个数字">
    <input type="button" value="计算" onclick="getResult()">
    <span id="span"></span>
    <script>
        function getResult() {
            let res = 1;
            let num = document.querySelector('input').value;
            for (let i = 1; i <= num; i++) {
                res *= i;
            }
            document.querySelector('span').innerHTML = res;
        }
    </script>
</body>

</html>